﻿/*
 * Сделано в SharpDevelop.
 * Пользователь: maxxadm
 * Дата: 23.05.2012
 * Время: 17:34
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using Microsoft.Win32;

namespace jellybird
{
	/// <summary>
	/// Description of OAuthKeyStore.
	/// </summary>
	public class OAuthKeySimpleStore
	{
		public OAuthKeySimpleStore()
		{
			restore_reg();
		}
		
		private const string REG_PATH=@"maxxSoft\jellybird\store";
		private const string CONSUMER_KEY="str_1";
		private const string CONSUMER_SECRET="str_2";
		private const string ACCESS_TOKEN="str_3";
		private const string TOKEN_SECRET="str_4";
		
		internal string ConsumerKey
		{
			get;set;
		}
		
		internal string ConsumerSecret
		{
			get;set;
		}
		
		internal string AccessToken
		{
			get;set;
		}
		
		internal string TokenSecret
		{
			get;set;
		}
		
		private void store_reg()
		{
			using(RegistryKey reg=Registry.CurrentUser.CreateSubKey(REG_PATH))
			{
				reg.SetValue(CONSUMER_KEY, ConsumerKey ?? string.Empty);
				reg.SetValue(CONSUMER_SECRET,ConsumerSecret ?? string.Empty);
				reg.SetValue(ACCESS_TOKEN,AccessToken ?? string.Empty);
				reg.SetValue(TOKEN_SECRET,TokenSecret ?? string.Empty);
			}
		}
		
		private void restore_reg()
		{
			using(RegistryKey reg=Registry.CurrentUser.CreateSubKey(REG_PATH))
			{
				ConsumerKey=reg.GetValue(CONSUMER_KEY,string.Empty) as string;
				ConsumerSecret=reg.GetValue(CONSUMER_SECRET,string.Empty) as string;
				AccessToken=reg.GetValue(ACCESS_TOKEN,string.Empty) as string;
				TokenSecret=reg.GetValue(TOKEN_SECRET,string.Empty) as string;
			}
		}
		
        /*
		internal void ShowDialog()
		{
			CredentialsWindow dial=new CredentialsWindow();
			dial.Owner=Program.JellybirdApplication.MainWindow;
			dial.CredAccessSecret.Text=TokenSecret;
			dial.CredAccessToken.Text=AccessToken;
			dial.CredConsumerKey.Text=ConsumerKey;
			dial.CredConsumerSecret.Text=ConsumerSecret;
			if(dial.ShowDialog()==true)
			{
				TokenSecret=dial.CredAccessSecret.Text;
				AccessToken=dial.CredAccessToken.Text;
				ConsumerKey=dial.CredConsumerKey.Text;
				ConsumerSecret=dial.CredConsumerSecret.Text;
				store_reg();
			}
		}
        */
	}
}
